<%@page import="java.io.PrintWriter"%>
<%@page import="com.scm.util.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>供应商</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../script/jquery-1.8.1.min.js"></script>
<style type="text/css">
	div.product{
		position: absolute;
		top:2px;
		left: 2px;
		width:100%;
		height: 98%;
		background-color: #fffffe;
	}

</style>
<script type="text/javascript">
	function test(){
		document.getElementById("con").style.display="block";
		}
	function goback(){
		window.location.href="../main/pomain/vender";
	}
	function add(){
		if($("[name=vendercode]").val().trim()==""){
			alert("供应商编号不能为空");
		}else if($("[name=name]").val().trim()==""){
			alert("供应商名称不能为空");
		}else if($("[name=contactor]").val().trim()==""){
			alert("联系人不能为空");
		}else if($("[name=tel]").val().trim()==""){
			alert("电话不能为空");
		}else if(!/[a-zA-Z0-9]{4,20}/.test($("[name=vendercode]").val())){
			alert("供应商编号不符合规范:4-20个字符，数字和字母 ");
		}else if(!/.{4,}/.test($("[name=password]").val())){
			alert("密码长度必须为4-20个字符");
		}else{
		var params = {vendercode:$("[name=vendercode]").val(),name:$("[name=name]").val(),password:$("[name=password]").val(),
				contactor:$("[name=contactor]").val(),address:$("[name=address]").val(),postcode:$("[name=postcode]").val(),
				createdate:$("[name=createdate]").val(),tel:$("[name=tel]").val(),fax:$("[name=fax]").val()};
		
		$.post("../main/pomain/addvender",params,function(data){alert(data);if(data=="添加成功"){window.location.href="vender_manage.jsp?op=add"}},"text");
		}
	}
	function change(){
		if($("[name=name]").val().trim()==""){
			alert("供应商名称不能为空");
		}else if($("[name=contactor]").val().trim()==""){
			alert("联系人不能为空");
		}else if($("[name=tel]").val().trim()==""){
			alert("电话不能为空");
		}else{
		var params = {vendercode:$("[name=vendercode]").val(),name:$("[name=name]").val(),password:$("[name=password]").val(),
				contactor:$("[name=contactor]").val(),address:$("[name=address]").val(),postcode:$("[name=postcode]").val(),
				createdate:$("[name=createdate]").val(),tel:$("[name=tel]").val(),fax:$("[name=fax]").val()};
		
		$.post("../main/pomain/changevender",params,function(data){alert(data),window.location.href="../main/pomain/vender"},"text");
		}
	}
</script>
</head>
<div >
</div>
<body>
<%
	String vendercode=request.getParameter("vendercode");
	String name = request.getParameter("name");
	String password = request.getParameter("password");
	String contactor = request.getParameter("contactor");
	String address = request.getParameter("address");
	String postcode = request.getParameter("postcode");
	String createdate = request.getParameter("createdate");
	String tel = request.getParameter("tel");
	String fax = request.getParameter("fax");
	String op = request.getParameter("op");
	pageContext.setAttribute("vendercode", vendercode);
	pageContext.setAttribute("name", name);
	pageContext.setAttribute("contactor", contactor);
	pageContext.setAttribute("address", address);
	pageContext.setAttribute("postcode", postcode);
	pageContext.setAttribute("createdate", createdate);
	pageContext.setAttribute("tel", tel);
	pageContext.setAttribute("fax", fax);
	pageContext.setAttribute("password", password);
	pageContext.setAttribute("op", op);
%>
<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td nowrap class="title1">您的位置：工作台面－－采购管理－－供应商管理</td>
  </tr>
</table>
<div class="formVisiblitly" id="formDiv"></div>
<form>
<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="30px" nowrap class="toolbar">&nbsp;</td>
  </tr>
</table>
<table id="headTable" width="100%"  border="0" align="center" class="a1">
  <tr align="justify">
    <td>供应商编号</td>
    <td>
     <c:if test="${op=='change' }"><input type="text" placeholder="4-20位数字字母" value="${vendercode }" size="15" name="vendercode" required readonly /></c:if> 
    <c:if test="${op=='add' }"><input type="text" value="${vendercode }" size="15" name="vendercode" required /></c:if>
      <span class="requred_symbol">*</span></td>
    <td>供应商的名称</td>
    <td><input type="text" size="15" name="name" value="${name}" required />
      <span class="requred_symbol">*</span>
      </td>
      <td>密码</td>
    <td><input type="password" size="15" name="password" placeholder="默认为供应商编号" value="${password }"/>
    </td>
    <td>联系人</td>
    <td><input type="text" size="15" name="contactor" value="${contactor}" required/>
        <span class="requred_symbol">*</span></td>
  </tr>
  <tr align="justify">
    <td>地址</td>
    <td><input type="text" size="15" name="address" value="${address}"/> </td>
    <td> 邮政编码</td>
    <td><input type="text" size="15" name="postcode" value="${postcode }"/></td>
    <td>注册日期</td>
    <td><input type="text" size="15" name="createdate" value="<%=DateUtil.currentDate()%>" readonly/></td>
    <td>电话</td>
    <td><input type="text" size="15" name="tel" value="${tel }" required/><span class="requred_symbol"> *</span></td>
   </tr>
  <tr align="justify">
    <td>传真</td>
    <td><input type="text" size="15" name="fax" value="${fax }"/></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
 
  <tr>
  	<td class="title2"></td>
  </tr>
</table>
<table width="100%"  border="0" align="center" cellspacing="1">
  <tr>
    <td class="title2"></td>
  </tr>
</table>
<br>
<div align="center">
<c:if test="${op=='add' }"><input type="button" id="bc" value="增加" onclick="add()"/></c:if>
<c:if test="${op=='change' }"><input type="button" id="bc" value="修改" onclick="change()"/></c:if>
    <input name="reset"  id="cz" value="重置" type="reset"/>
    <input type="button" id="gb" value="关闭" onClick="goback()"/>
</div>
</form>
 
</body>
</body>
</html>